#[derive(Debug)]
struct ClosureDemo {}

pub fn simple_closure() {
    let new_num = |num: i32| -> i32{
        num * 2
    };
    println!("new_num is {}", new_num(3));
}

#[test]
fn simple_closure_test() {
    simple_closure();
}

#[derive(PartialEq, Debug)]
struct Shoe {
    size: u32,
    style: String,
}

fn shoes_my_size(shoes: Vec<Shoe>, shoe_size: u32) -> Vec<Shoe> {
    shoes.into_iter()
        .filter(|s| s.size == shoe_size)
        .collect()
}

pub fn filter_by_size() {
    let shoes = vec![
        Shoe { size: 10, style: String::from("yellow") },
        Shoe { size: 5, style: String::from("red") },
        Shoe { size: 10, style: String::from("blue") },
    ];
    let my_size = shoes_my_size(shoes, 10);
    for shoe in my_size.iter() {
        println!("my like color is {}", shoe.style);
    }
}

pub struct Counter {
    count: u32,
}

impl Counter {
    pub fn new() -> Counter {
        Counter { count: 0 }
    }
}

impl Iterator for Counter {
    type Item = u32;
    fn next(&mut self) -> Option<Self::Item> {
        self.count += 1;
        if self.count < 6 {
            return Some(self.count);
        } else { return None; }
    }
}

#[test]
fn count_sum_test() {
    let count = Counter::new();

//    let sum: u32 = count.zip(Counter::new().skip(1)).map(|(a, b)| a * b)
//        .filter(|x| x % 3 == 0).sum();

    let sum: u32 = count.zip(Counter::new().skip(1)).map(|(a, b)| a * b).sum();
//        .filter(|x| x % 3 == 0).sum();

    println!("sum is {}", sum);
}